package com.nbsaas.boot.controller.product;

import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import com.nbsaas.boot.product.api.domain.request.ProductFavoritesRequest;
import com.nbsaas.boot.product.api.domain.request.ProductFavoritesSearch;
import com.nbsaas.boot.product.api.domain.response.ProductFavoritesResponse;
import com.nbsaas.boot.product.api.domain.simple.ProductFavoritesSimple;
import com.nbsaas.boot.product.api.apis.ProductFavoritesApi;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource;

/**
*  产品收藏控制器
*/
@RequiresAuthentication
@RestController
@RequestMapping("/productFavorites")
public class ProductFavoritesController {


    @Resource
    private ProductFavoritesApi productFavoritesApi;

    /**
    * 搜索数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("productFavorites:search")
    @PostMapping("/search")
    public PageResponse <ProductFavoritesSimple> search(@RequestBody ProductFavoritesSearch request) {
        return productFavoritesApi.search(request);
    }

    /**
    * 列表数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("productFavorites:list")
    @PostMapping("/list")
    public ListResponse<ProductFavoritesSimple> list(@RequestBody ProductFavoritesSearch request) {
        return productFavoritesApi.list(request);
    }

    /**
    * 添加数据
    *
    * @param request
    * @return
    */
    @RequiresPermissions("productFavorites:create")
    @CreateData
    @PostMapping("/create")
    public ResponseObject <ProductFavoritesResponse> create(@RequestBody @Validated(AddOperator.class) ProductFavoritesRequest request) {
        return productFavoritesApi.create(request);
    }

   /**
   * 修改数据
   * @param request
   * @return
   */
   @RequiresPermissions("productFavorites:update")
   @UpdateData
   @PostMapping("/update")
   public ResponseObject<ProductFavoritesResponse> update(@RequestBody @Validated(UpdateOperator.class) ProductFavoritesRequest request) {
       return productFavoritesApi.update(request);
   }

    /**
    * 删除数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("productFavorites:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) ProductFavoritesRequest request) {
        return productFavoritesApi.delete(request);
    }

    /**
    * 查看数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("productFavorites:view")
    @PostMapping("/view")
    public ResponseObject <ProductFavoritesResponse> view(@RequestBody @Validated(ViewOperator.class) ProductFavoritesRequest  request) {
        return productFavoritesApi.view(request);
    }
}